import request from '@/utils/request'

// 获取所有的Role
export function getAll() {
  return request({
    url: 'api/roles/all',
    method: 'get'
  })
}

export function add(obj) {
  return request({
    url: 'admin/role/add',
    method: 'post',
    data:obj
  })
}

export function get(id) {
  return request({
    url: 'api/roles/' + id,
    method: 'get'
  })
}

export function getLevel() {
  return request({
    url: 'api/roles/level',
    method: 'get'
  })
}

export function del(ids) {
  return request({
    url: 'admin/role/del',
    method: 'post',
    data: ids
  })
}

export function edit(obj) {
  return request({
    url: 'admin/role/edit',
    method: 'post',
    data:obj
  })
}

export function editMenu(data) {
  return request({
    url: 'api/roles/menu',
    method: 'put',
    data
  })
}

/**
 * 角色菜单关系
 */
export function addRoleMenus(obj) {
  return request({
    url: 'admin/role/add-role-menu',
    method: 'post',
    data: obj
  })
}

/**
 * 通过角色获取菜单
 */
export function getMenusByRole(obj) {
  return request({
    url: 'admin/role/get-menu/by-id/'+obj,
    method: 'get'
  })
}
/**
 * 通过角色获取菜单
 */
export function getRoleList() {
  return request({
    url: 'admin/role/list',
    method: 'get'
  })
}

export default { add, edit, del, get, editMenu, getLevel,addRoleMenus,getMenusByRole,getRoleList }
